export interface stateType {
    num: number
}
const state: {
    actionsName: {
        [k: string]: string
    }
    state: stateType
    actions: {
        [k: string]: Function
        add1: Function
        add2: Function
    },
    asyncAction: {
        [k: string]: Function
    }
} = {
    actionsName: {},
    state: {
        num: 5
    },
    // 同步方法
    actions: {
        add1(newState: stateType, action: any) {
            newState.num++
        },
        add2(newState: stateType, action: any) {
            newState.num += action.n
        }
    },
    // 异步方法
    asyncAction: {
        async_add1(dispatch:Function) {
            setTimeout(() => {
                dispatch({ type: state.actionsName.add1 })
            }, 1000)
        }
    }
}
let actionsName: { [k: string]: string } = {}
for (const key in state.actions) {
    actionsName[key] = key
}
state.actionsName = actionsName

export default state
